module.exports = function ($scope, $resource, $modal, toaster, $state){

    $scope.searchform = {};

    /* 分页
       * ========================================= */
    $scope.maxSize = 5;            //最多显示多少个按钮
    $scope.bigCurrentPage = 1;      //当前页码
    $scope.itemsPerPage = 10;         //每页显示几条

    $scope.load = function () {
        var para = {
            pageNo: $scope.bigCurrentPage,
            pageSize: $scope.itemsPerPage
        };

        angular.extend(para, $scope.searchform);

        $resource('/api/as/goc/enterpriserecord/collectionlist', {}, {}).save(para, function (res) {
            console.log(res);

            if (res.errcode !== 0) {
                toaster.error({title: '', body: res.errmsg});
                return;
            }

            $scope.objs = res.data.results;
            $scope.bigTotalItems = res.data.totalRecord;

        });
    };
    $scope.load();

    //打开模态框
    $scope.edit = function(obj){
     
        var para = $state.get('app.collectioninfo');
        var resolve = {
            obj : function(){
                return obj;
            },
        };
        angular.extend(para.resolve, resolve);

        var modalInstance = $modal.open(para);
        modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
            console.log('modal is opened');  
        });  
        modalInstance.result.then(function(result) {  

        }, function(reason) {  
            console.log(reason);// 点击空白区域，总会输出backdrop  
            // click，点击取消，则会暑促cancel  
            $log.info('Modal dismissed at: ' + new Date());  
        }); 
    }

    //导入excel
    $scope.excel = function (obj) {
        var router_para = $state.get('app.updatecollection');
         var resolve = {
            obj : function(){
                return obj;
            },
        };
        angular.extend(router_para.resolve, resolve);
        var modalInstance = $modal.open(router_para);

        modalInstance.opened.then(function() {// 模态窗口打开之后执行的函数  
            console.log('modal is opened');  
        });  
        modalInstance.result.then(function(result) {
            var para = {
                'id' : result.id
            };
            for (var key in result[0]) {
                switch(key)
                {
                    case '采集的企业名称': para['collection_name']=result[0][key]; break;
                    case '采集的统一社会信用代码': para['collection_company_code']=result[0][key]; break;
                    case '采集的营业执照编码': para['collection_business_license_code']=result[0][key]; break;
                    case '采集的企业注册地址': para['collection_registered_address']=result[0][key]; break;
                    case '采集的公司类型': para['collection_company_type']=result[0][key]; break;
                    case '采集的注册资金汉字大写': para['collection_registered_capital']=result[0][key]; break;
                    case '采集的注册时间': para['collection_company_start_date']=result[0][key]; break;
                    case '采集的营业期限': para['collection_company_end_date']=result[0][key]; break;
                    case '采集的公司电话、传真': para['collection_phone']=result[0][key]; break;
                    case '采集的负责人名字': para['collection_responsible_name']=result[0][key]; break;
                    case '采集的负责人身份证号': para['collection_responsible_no']=result[0][key]; break;
                    case '采集的负责人手机': para['collection_responsible_mobile']=result[0][key]; break;
                    case '采集的联系地址': para['collection_contact_address']=result[0][key]; break;
                    case '采集的法人': para['collection_juridical_person']=result[0][key]; break;
                    case '采集的经营范围': para['collection_business_scope']=result[0][key]; break;
                }
            }

            $resource('/api/as/goc/enterpriserecord/updatecollection', {}, {}).save(para, function(res){
                if (res.errcode === 0) {
                    toaster.success({title: '', body: '保存成功'});
                    $scope.load();
                } else {
                    toaster.error({title: '', body: res.errmsg});
                }
            });
        }, function(reason) {  
            console.log(reason);// 点击空白区域，总会输出backdrop  
            // click，点击取消，则会暑促cancel  
            $log.info('Modal dismissed at: ' + new Date());  
        }); 
    }



};